import React, {Component} from 'react';
import {observer} from 'mobx-react';
import {Icon, Tools} from 'weaver-mobile';
import classnames from 'classnames';
import SignBtn from './SignBtn';
const getLabel = Tools.getLabel;

@observer
export default class Content extends Component{
    render(){
        const {data, activeIndex, currIndex, store: {callSign, showWorkflow}, redirectToOutsideSign} = this.props;
        const {store,label} = this.props;
        const statusObj = this.props.convertStatus(data.status || data.signfrom || '');
        const obj = {
            status: true
        }
        statusObj != null && Object.assign(obj, {[statusObj.className]: true});
        const statusClassName = classnames(obj);

        return (
            <div className='info-content'>
                <div className='time'>{label}</div>
                {
                    ((activeIndex === -1 || activeIndex > currIndex) && (data.signTime != null && data.signTime.trim().length > 0)) &&
                    <div className='signData'>
                    {
                        data.signTime != null && data.signTime.trim().length > 0 &&
                        <div className='signTime'>{`${getLabel('18949','打卡时间')} ${data.signbelongspan || ''} ${data.signTime}`}</div>
                    }
                    {
                        ((activeIndex === -1 || activeIndex > currIndex) || (data.signTime != null && data.signTime.trim().length > 0)) &&
                        <div className={statusClassName}>{statusObj.label}</div>
                    }
                    </div>
                }
                {
                    data.position != null && data.position.trim().length > 0 &&
                    <div className='position'>
                        <Icon className='positionIcon' type='position' size='xxs'/>
                        <div className='positionInfo'>{data.position}</div>
                    </div>
                }
                {
                    data.reSign == '1' &&
                    <div className='resign' onClick={() => callSign(data, redirectToOutsideSign)}>{getLabel('500498','更新打卡时间')}</div>
                }
                {
                    ((activeIndex === -1 || activeIndex > currIndex) && data.status != null && ['0', '1'].indexOf(data.status) < 0) &&
                    <div className='workflow' onClick={() => showWorkflow()}>{getLabel('500499','提交流程')}</div>
                }
                {
                    (data.needSign === '' || data.needSign === '1') && 
                    <SignBtn {...this.props} />
                }
            </div>
        )
    }
}